﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace MvvmTutorials.ToolkitIntro
{
    public partial class MainWindowViewModel : ObservableObject
    {
        [ObservableProperty]
        //[NotifyPropertyChangedFor(nameof(Caption))]
        private string title = "Hello World!";

        partial void OnTitleChanged(string value)
        {
            OnPropertyChanged(nameof(Caption));
        }

        public string Caption => $"Title: {Title}";

        [ObservableProperty]
        [NotifyCanExecuteChangedFor(nameof(ButtonClickCommand))]
        private bool isEnabled;

        public MainWindowViewModel()
        {
            // ButtonClickCommand = new RelayCommand(() => Title = "Button Clicked", () => IsEnabled);
        }

        [RelayCommand(CanExecute = nameof(CanButtonClick))]
        private async Task ButtonClickAsync()
        {
            await Task.Delay(1500);
            Title = "Good Bye";
        }

        private bool CanButtonClick() => IsEnabled;
    }
}
